{extend name="base"/}
{block name="title"}
    购物车
{/block}
{block name="css"}
<link rel="stylesheet" href="__MOBILE__/css/zhang.css">
{/block}
{block name="content"}
<div class="header">
    <div class="header_del">编辑</div>
    <div class="header_tit">购物车(<span>2</span>)</div>
    <div class="header_mess"><a href="{:url('/langjinmobile/my/usermessage')}"><img src="__MOBILE__/images/mess.png" alt=""></a></div> 
</div>
{if count($datas)>0 }
<ul class="goods">
	{volist name="datas" id="vo"}

    <li>
        <div class="choose">
           <p></p>
        </div>
        <div class="oimg">
        	<input type="hidden" value="{$vo.car_id}">
            <img src="{$vo.img1}" alt="">
        </div>
        <div class="goods_right">
            <p class="name_of">商品：{$vo.good_name}</p>
            <div class="spec">
                <p>店铺：<span>{$vo.business.name}</span></p>
                <p>X<span class="num">{$vo.num}</span></p>
            </div>
            <div class="all">
				<p>￥<span class="price">{$vo.wallet_num}</span></p><p>+</p><p><span class="prices">{$vo.integral_num}</span>GMOD</p>
            </div>
        </div>
    </li>
    {/volist}
    
    
</ul>
{/if}

<div class="shop_footer">
    <div class="shop_footer_left">
        <p></p><div>全选</div>
    </div>
    <div class="shop_footer_right">
        <p>￥<span>0</span></p><a href="###" class="jiesuan">结算</a><a href="###" class="delete">删除</a>
    </div>
</div>

<div class="footer">
	<a href="{:url('/langjinmobile/home/index')}">
		<img src="__MOBILE__/images/footer1.png" alt="">
		<p>首页</p>
	</a>
	<a href="{:url('/langjinmobile/classify/index')}">
		<img src="__MOBILE__/images/footer3.png" alt="">
		<p>分类</p>
	</a>
	<a href="{:url('/langjinmobile/card/shopcard')}"  class="active">
		<img src="__MOBILE__/images/footer6.png" alt="">
		<p>购物车</p>
	</a>
	<a href="{:url('/langjinmobile/my/my')}">
		<img src="__MOBILE__/images/footer7.png" alt="">
		<p>我的</p>
	</a>
</div>

{/block}
{block name="js"}
<script type="text/javascript">
	var a = 0;
	var att = 0;
	var jifen = 0;
	var c = 0;
    $(".header_tit span").html($(".goods li").length);
    function all_tol(){
			var $elements = $('.ok_choose');
			var len = $elements.length;
			att = 0;
			jifen = 0;
			for(var i = 0; i < len; i++){
                att = att + parseInt(parseInt($(".ok_choose").parents("li").eq(i).find(".price").html())*parseInt($(".ok_choose").parents("li").eq(i).find(".num").html()));
				jifen = jifen + parseInt(parseInt($(".ok_choose").parents("li").eq(i).find(".prices").html())*parseInt($(".ok_choose").parents("li").eq(i).find(".num").html()));
				$(".shop_footer_right span").html(att +' + '+ jifen +' GMOD');
			}
		};
		
		function visvib(){
			$(".header_del").html("完成");
			$(".jiesuan").hide();
            $(".delete").show();
		};
		
		
		$(".choose p").click(function(){
			if($(this).hasClass("ok_choose")){
				var Oindex = $(this).parent().parent().index();
				$(this).removeClass("ok_choose");
				att = att - parseInt($("li .price").eq(Oindex).html())*parseInt($(".num").eq(Oindex).html());
				jifen = jifen - parseInt($("li .prices").eq(Oindex).html())*parseInt($(".num").eq(Oindex).html());
				$(".shop_footer_right span").html(att +' + '+ jifen +' GMOD');
			}else{
				var Oindex = $(this).parent().parent().index();
				$(".choose p").eq(Oindex).addClass("ok_choose");
				att = 0;
				jifen = 0;
				all_tol();
			}
			var Emlen = $(".choose p").length;
			var $elements = $('.ok_choose');
			var len = $elements.length;
			if(len == Emlen){
				$(".shop_footer_left p").addClass("active");
				$(".shop_footer_left div").html("全不选");
				a = 1;
			}else if(len != Emlen){
				$(".shop_footer_left p").removeClass("active");
				$(".shop_footer_left div").html("全选");
				a = 0;
			}
		});
		
		$(".shop_footer_left p").click(function(){
			att = 0;
			if(a == 0){
				$(".shop_footer_left p").addClass("active");
				$(".shop_footer_left div").html("全不选");
				$(".choose p").addClass("ok_choose");
				a = 1;
				all_tol();
			}else{
				$(".shop_footer_left p").removeClass("active");
				$(".shop_footer_left div").html("全选");
				$(".choose p").removeClass("ok_choose");
				a = 0;
				$(".shop_footer_right span").html(0);
			}
		});
		$(".header_del").click(function(){
			if(c == 0){
				visvib();
				c = 1;
			}else{
                $(".header_del").html("编辑");
                $(".jiesuan").show();
                $(".delete").hide();
				c = 0;
			}
		});
		
		$(".delete").click(function(){
            var Oid = [];
            var $elements = $('.ok_choose');
			var len = $elements.length;
			for(var i = 0; i < len; i++){
				Oid.push($(".ok_choose").eq(i).parents("li").find("input").val());
			}
			console.log(Oid);
			$.post('/langjinmobile/Card/deletecart',{Oid},function(res){
	            console.log(res);
	            if(res.status==1){
	                msg_alert(res.msg);
	                $(".ok_choose").parent().parent().remove();
					$(".shop_footer_right span").html("0");
					visvib();
		            $(".header_tit span").html($(".goods li").length);        
	            }
	        })
			
		});


		

    $(".jiesuan").click(function(){
        if($(".shop_footer_right").find("span").html() != 0){
			var Oid = [];
			var Onum = [];
            var $elements = $('.ok_choose');
			var len = $elements.length;
			for(var i = 0; i < len; i++){
				Oid.push($(".ok_choose").eq(i).parents("li").find("input").val());
				Onum.push($(".ok_choose").eq(i).parents("li").find(".num").html());
			}
			console.log(Oid);
			console.log(Onum);
			$.post('/langjinmobile/Card/makesure',{info:Onum,ids:Oid},function(res){
                 console.log(res);
                if(res.status==1){
                    window.location.href = "/langjinmobile/Card/makesure";        
                }else{
                    msg_alert(res.msg);     
                }
            })
        }else{
            msg_alert("请选择要结算的商品");
        }
    });
</script>

{/block}